package org.twdata.pipeline;

import java.util.*;

/**
 *  An executable process to transform input composed of an XML generator, zero
 *  or more transformers, and a serializer. Each stage of the pipeline is built
 *  using stage builders which manage the lifecycle and configuration of the
 *  stage.
 */
public abstract class MutablePipeline implements Pipeline {

    /**  List of transformer builders */
    protected List transformerBuilders = new ArrayList();
    /**  The stage builder for the generator */
    protected StageBuilder generatorBuilder;
    /**  The stage builder for the serializer */
    protected StageBuilder serializerBuilder;
    /**  The stage manager for managing stage lifecycles */
    protected StageManager stageManager;
    /**  The name of the pipeline */
    protected String name;


    /**
     *  Sets the name of the pipeline
     *
     *@param  name  The new name value
     */
    public void setName(String name) {
        this.name = name;
    }


    /**
     *  Gets the name of the pipeline
     *
     *@return    The name value
     */
    public String getName() {
        return name;
    }


    /**
     *  Sets the value of generatorBuilder.
     *
     *@param  generatorBuilder  The value to assign generatorBuilder.
     */
    public void setGeneratorBuilder(StageBuilder generatorBuilder) {
        this.generatorBuilder = generatorBuilder;
    }


    /**
     *  Sets the value of transformerBuilders.
     *
     *@param  transformerBuilders  The value to assign transformerBuilders.
     */
    public void setTransformerBuilders(List transformerBuilders) {
        this.transformerBuilders = transformerBuilders;
    }


    /**
     *  Adds a transformer builder to the list.
     *
     *@param  transformerBuilder  The new builder.
     */
    public void addTransformerBuilder(StageBuilder transformerBuilder) {
        this.transformerBuilders.add(transformerBuilder);
    }


    /**
     *  Sets the value of serializerBuilder.
     *
     *@param  serializerBuilder  The value to assign serializerBuilder.
     */
    public void setSerializerBuilder(StageBuilder serializerBuilder) {
        this.serializerBuilder = serializerBuilder;
    }


    /**
     *  Executes the pipeline. 
     *
     *@param  ctx                    The context information
     *@exception  PipelineException  If something goes wrong
     */
    public abstract void execute(PipelineContext ctx)
        throws PipelineException;
}

